import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class PicGen extends JFrame implements ActionListener{
    static PicGen window;
    MainWindow main;
    JTextField width;
    JTextField height;
    JTextField shade;
	JTextField winHeight;
	JTextField winWidth;
    JComboBox random;

    public static void main(String args[]){
        window = new PicGen();
        window.setVisible(true);
    }
    public PicGen(){
            JPanel content = new JPanel();
            setSize(350,350);
            setVisible(true);
            setResizable(false);
            setLocation(20,20);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            getContentPane().add(content);
            content.setLayout(new BorderLayout());
            JPanel welcome = new JPanel();
            JLabel name = new JLabel("PicGen 1.2");
            JLabel author = new JLabel("Made by: Quinn Damerell");
            
            welcome.add(name);
            welcome.add(author);
            content.add(welcome, BorderLayout.NORTH); 
            
            JPanel infoHolder = new JPanel();
            infoHolder.setLayout(new FlowLayout());
            
            JPanel info = new JPanel();
            info.setLayout(new GridLayout(7,4,10,10));
            
            JLabel widthL = new JLabel("Picture Width (2~800)");
            JLabel heightL = new JLabel("Picture Height (2~600)");
			JLabel windowWidth = new JLabel("Window Width (2~800)");
            JLabel windowHeight = new JLabel("Window Height (2~600)");
            JLabel shadeL = new JLabel("Shade Detail (2~255)");
            JLabel randomL = new JLabel("Start With Random Pixles");

            width = new JTextField("5");
            height = new JTextField("5");
            shade = new JTextField("90");
			winWidth = new JTextField("400");
			winHeight = new JTextField("400");
            String[] opt = {"Yes","No"};
            random = new JComboBox(opt);

            JButton start = new JButton("Start");
            start.addActionListener(this);
			
			info.add(windowWidth);
			info.add(winWidth);
			info.add(windowHeight);
			info.add(winHeight);
            info.add(widthL);
            info.add(width);
            info.add(heightL);
            info.add(height);
            info.add(shadeL);
            info.add(shade);
            info.add(randomL);
            info.add(random);
            
            infoHolder.add(info);
            infoHolder.add(start);            
            content.add(infoHolder, BorderLayout.CENTER);
    }
	public void startUp(){
		int[] res;
		res = new int[6];
		res[0] = Integer.parseInt(width.getText());
		res[1] = Integer.parseInt(height.getText());
		res[2] = Integer.parseInt(shade.getText());
		res[3] = random.getSelectedIndex();
		res[4] = Integer.parseInt(winWidth.getText());;
		res[5] = Integer.parseInt(winHeight.getText());;
		window.setVisible(false);
		main = new MainWindow(res[4],res[5],res[0],res[1],res[3],res[2]);		
		main.setVisible(true);		
		main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		main.runLoop();
	}
	
    public void actionPerformed(ActionEvent e){
        if (e.getActionCommand().equals("Start")){
            window.startUp();
        }
    }
}